import * as type from './mutations-types'

export default {
    // mutations里面定义方法的时候会自动传入state参数
    [type.INCREMENT](state) {
        state.count++;
    },
    // ['decrement'] 和 decrement 的写法是一样的
    // ['decrement'](state) {
    //     state.count--;
    // },
    [type.DECREMENT]: state => { state.count-- },

    // incrementCount(state, number) {
    //     state.count += number;
    // },
    // 如果用特殊的提交风格，后面的参数要写成载荷payload，然后再到payload里面去取参数
    [type.INCREMENTCOUNT](state, payload) {
        // console.log(payload);
        // console.log(payload.number);
        state.count += payload.number;
    },
    [type.ADDSTUDENT](state, stu) {
        state.students.push(stu);
    },

    [type.UPDATAINFO](state, payload) {
        // 响应式更改属性
        state.info.name = payload.name;
    },
    [type.ADDPROPONE](state) {
        // 给info增加新的属性,但未添加到state中，不能做到响应式
        state.info['address'] = 'L.A. 洛杉矶';
        console.log(state.info);
    },
    [type.ADDPROPTWO](state) {
        // 响应式的添加属性
        // Vue.set(修改的对象，key，value)
        Vue.set(state.info, 'addressTwo', '广东');
    },
    [type.DELAGEPROP](state) {
        // 不能响应式的删掉属性
        delete state.info.age;
    },
    [type.DELAGEPROPTWO](state) {
        // 响应式的删除age属性
        Vue.delete(state.info, 'age');
    },
    [type.ASYNCUPDATAmESSAGE](state, payload) {
        // saync异步 更新信息(不能在Mutations里进行异步操作)
        setTimeout(() => {
            state.info.name = payload.name;
        }, 1000);
    },
    [type.ACTIONSUPDATAMESSAGE](state) {
        state.info.name = 'coderWhy';
    },
    [type.ACTIONSUPDATAAGE](state, payload) {
        state.info.age = payload.age;
    },
    [type.SUCCESSDUPDATA](state) {
        state.info.height = '2米';
    },
    [type.SUCCESSDUPDATAMESSAGE](state, payload) {
        state.info.height = payload.height
    },
    [type.SUCCESSDUPDATAMESSAGE_GOOD](state, payload) {
        state.info.height = payload.height
    },
}